package algotithm.leetcode.listnode.test203;

import algotithm.leetcode.listnode.ListNode;

/**
 * @author zhouyanxiang
 * @Date 2021-02-2021/2/20-18:54
 * @URL https://leetcode-cn.com/problems/remove-linked-list-elements/
 * @Title 203. 移除链表元素
 */
public class Solution {


    public ListNode removeElements(ListNode head, int val) {
        if (head == null) {
            return head;
        }
        if (head.val == val) {
            return removeElements(head.next,val);
        }
        ListNode fast = head.next;
        ListNode slow = head;
        while (fast != null) {
            if (fast.val != val) {
                fast = fast.next;
                slow = slow.next;
            } else {
                slow.next = fast.next;
                fast = fast.next;
            }
        }
        return head;

    }

}
